<template>
    <div>
        <div class="mv-info">
            <div class="w">
                <video
                ref="video"
                controls
                :src="mvUrl"></video>
                <div class="mv-info" v-if="mvData != null">
                    <span class="m">{{mvName}}</span>
                    <span class="space">-</span>
                    <span @click="jumpSingerInfo(mvData.artists[0].id)" class="m name">{{mvSinger}}</span>
                </div>
            </div>
        </div>
        
        <div class="some w">
            <div class="title">大部分人还爱看</div>
            <div class="list" v-if="someMV != null">
                <div
                @click="jumpMVInfo(item)"
                :key="index"
                v-for="(item, index) in someMV"
                class="item">
                    <div class="pic">
                        <div class="mask">
                            <span class="iconfont">&#xe682;</span>
                        </div>
                        <img :src="item.coverUrl">
                    </div>
                    <div class="mv-name">{{item.title}}</div>
                    <div class="singer-name">{{item.creator[0].userName}}</div>
                </div>
            </div>
        </div>

        <div class="des w">
            <div class="title">视频简介</div>
            <div class="contenr" v-if="mvDes != '' && mvDes != null">
                {{mvDes}}
            </div>
            <div class="contenr" v-if="mvDes == '' || mvDes == null">
                该视频暂无简介...
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            // MVID
            mvID: 0,
            // MV数据
            mvData: null,
            // mv地址
            mvUrl: '',
            // 相关视频
            someMV: null,
            // 视频简介
            mvDes: '',
            // mv名称
            mvName: '',
            // 歌手
            mvSinger: ''
        }
    },
    mounted() {
        var params = location.hash.split('/');
        this.mvID = params[params.length - 1];
        this.getMVData();
        this.getMVUrl();
        this.someMVs();
    },
    methods: {
        // 获取mv数据
        async getMVData() {
            let { data: res } = await this.$http.get('/mv/detail', { params: { mvid: this.mvID } });
            this.mvData = res.data;
            this.mvDes = this.mvData.desc;
            this.mvName = this.mvData.name;
            this.mvSinger = this.mvData.artistName;
        },
        // 获取mv地址
        async getMVUrl() {
            let { data: res } = await this.$http.get('/mv/url', { params: { id: this.mvID } });
            this.mvUrl = res.data.url;
            this.$nextTick(() => {
                this.waterMVStar();
            })
        },
        // 跳转到歌手详情
        jumpSingerInfo(id) {
            this.$router.push(`/singer/info/${id}`);
        },
        // 监控mv开始播放
        waterMVStar() {
            this.$refs.video.addEventListener('playing', () => {
                // 让播放音乐暂停
                this.$emit('stopMusic');
            });
        },
        // 获取相关视频
        async someMVs() {
            let { data: res } = await this.$http.get('/related/allvideo', { params: { id: this.mvID } });
            this.someMV = res.data;
        },
        // 跳转到其它MV
        async jumpMVInfo(item) {
            try {
                let { data: res } = await this.$http.get('/video/detail', { params: { id: item.vid } });
                this.mvID = item.vid;
                this.mvDes = res.data.description;
                this.mvName = res.data.title;
                this.mvSinger = res.data.creator.nickname;
                this.getSomeMVUrl();
            } catch (error) {
                this.$message.error('此视频暂无版权，或者数据出错，请尝试观看其他视频！');
            }
        },
        // 获取其它MV播放地址
        async getSomeMVUrl() {
            try {
                let { data: res } = await this.$http.get('/video/url', { params: { id: this.mvID } });
                this.mvUrl = res.urls[0].url;
                window.scrollTo(0, 0);
            } catch (error) {
                this.$message.error('此视频暂无版权，或者数据出错，请尝试观看其他视频！');
            }
        }
    }
}
</script>

<style lang="less" scoped>
.mv-info {
    height: 750px;
    width: 100%;
    background-color: #333333;
    overflow: hidden;
    .w {
        height: 750px;
        overflow: hidden;
    }
}

video {
    width: 100%;
    height: 670px;
    border: none;
    outline: none;
    margin-bottom: 20px;
}

.mv-info {
    .m {
        font-size: 20px;
        color: #fff;
    }
    .name {
        cursor: pointer;
        &:hover {
            color: #48c686;
        }
    }
    .space {
        display: inline-block;
        margin: 0 12px;
        color: #fff;
    }
}

.some {
    margin-top: 26px;
    .title {
        font-size: 26px;
        margin-bottom: 20px;
    }
    .list {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        .item {
            width: 18%;
            margin-bottom: 20px;
            .pic {
                position: relative;
                width: 100%;
                height: 128px;
                cursor: pointer;
                &:hover .mask {
                    display: block;
                }
                img {
                    width: 100%;
                    height: 100%;
                }
                .mask {
                    display: none;
                    position: absolute;
                    width: 100%;
                    height: 100%;
                    background: rgba(0, 0, 0, .4);
                    &:hover .iconfont {
                        font-size: 50px;
                        opacity: 1;
                    }
                    .iconfont {
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                        font-size: 10px;
                        opacity: 0;
                        transition: all .3s;
                        color: #fff;
                        font-weight: 700;
                    }
                }
            }
            .mv-name {
                margin-top: 10px;
                margin-bottom: 4px;
                &:hover {
                    color: #48c686;
                }
            }
            .mv-name,
            .singer-name {
                font-size: 14px;
                cursor: pointer;
            }
        }
    }
}


.des {
    margin-top: 20px;
    .title {
        font-size: 26px;
        margin-bottom: 20px;
    }
    .contenr {
        letter-spacing: 2px;
        font-size: 14px;
        line-height: 20px;
        color: #414441;
        padding-bottom: 50px;
    }
}
</style>